package com.weipai.education.controller;

import com.weipai.education.model.Activity;
import com.weipai.education.model.User;
import com.weipai.education.model.api.Response;
import com.weipai.education.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * @Author: 曹朋飞
 * @Date: 2018/12/11 10:31
 * 
 * 活动控制类
 */
@RestController
public class ActivityController {
    
    @Autowired
    private ActivityService activityService;

    /**
     * 分页查询
     * @param page
     * @param size
     * @param isAudit
     * @param activityCateId
     * @param key
     * @param type:为空查询所有，为own查询自己
     * @return
     */
    @RequestMapping(value = "/activity/list", method = RequestMethod.GET)
    public Response list(@NotNull(message = "page不能为空") @RequestParam(value = "page") Integer page,
                         @NotNull(message = "size不能为空") @RequestParam(value = "size") Integer size,
                         @RequestParam(value = "isAudit", required = false) Integer isAudit,
                         @RequestParam(value = "activityCateId", required = false) Integer activityCateId,
                         @RequestParam(value = "key", required = false) String key,
                         @RequestParam(value = "type", required = false) String type){
        return activityService.list(page, size, isAudit, activityCateId, key, type);
    }

    /**
     * 活动保存--修改
     * @param activity
     * @return
     */
    @RequestMapping(value = "/activity/save", method = RequestMethod.POST)
    public Response save(@Valid Activity activity){
        return activityService.save(activity);
    }

    /**
     * 审核活动
     * @param id
     * @return
     */
    @RequestMapping(value = "/activity/isAudit", method = RequestMethod.GET)
    public Response isAudit(@NotBlank(message = "活动id不能为空") String id, @NotBlank(message = "审核状态不能为空")String isAudit){
        return activityService.isAudit(id, isAudit);
    }

    /**
     * 批量删除
     * @param id:
     * @return
     */
    @RequestMapping(value = "/activity/batchDeleteById", method = RequestMethod.GET)
    public Response batchDeleteById(@NotBlank(message = "活动id不能为空") String[] id){
        return activityService.batchDeleteById(id);
    }
    
    
}
